 package com.suozq.current.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 锁战强
 * @date 2022/04/13
 */
public class ThreadPoolTest {
    public static void main(String[] args) {
        ForkJoinPool.commonPool();
        ExecutorService cachedPool = Executors.newCachedThreadPool();
        ExecutorService fixPool = Executors.newFixedThreadPool(4);
        Executors.newSingleThreadExecutor();
        ExecutorService tp = new ThreadPoolExecutor(6,6,10,TimeUnit.SECONDS,new LinkedBlockingDeque<>(100),new ThreadPoolExecutor.CallerRunsPolicy());
        for(int i=0;i<Integer.MAX_VALUE;i++) {
            final int j = i;
            tp.execute(()->{
                try {
                    Thread.sleep(100);
                    System.out.println(Thread.currentThread().getName()+"结束:"+j);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            System.out.println("循环添加"+i);
        }
        System.gc();
        System.out.println(tp);
    }
}   
